package com.sskj.b70.p.activity;

import com.lzy.okgo.model.Response;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.common.Constants;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.bean.UserInfo;
import com.sskj.b70.m.bean.bean.FbShop;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.SPUtils;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.activity.SellerApplyActivity;

import java.util.List;


public class SellerApplyPresenter extends BasePresenter<SellerApplyActivity> {

    public void apply() {
        httpService.applyShop(MyAppLication.getID(), "2")
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        if (response.body().getStatus() == HttpConfig.STATUS_OK) {
                            mView.startFabiPublish();
                        } else {
                            ToastUtil.showShort(response.body().getMsg());
                        }
                    }
                });
    }

    public void fbShopNumber() {
        httpService.moneyUsed("fb_shop", "3")
                .execute(new JsonCallBack<HttpData<List<FbShop>>>(this, false) {
                    @Override
                    public void _onSuccess(Response<HttpData<List<FbShop>>> response) {
                        HttpData<List<FbShop>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
//                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_IS_SHOP, httpData.getData().is_shop);
                            mView.updateUser(httpData.getData().get(0));
                        }
                    }

                });
    }

    public void requestUserInfo() {
        httpService.getUserInfo()
                .execute(new JsonCallBack<HttpData<UserInfo>>(this, false) {
                    @Override
                    public void _onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_IS_SHOP, httpData.getData().isIs_shop());
                        }
                    }

                });
    }
}
